import request from '@/utils/request.js'
import file from '@/utils/file.js'

// 注册函数，传入用户名和密码，返回请求结果
export const register = (username, password, avatar = "") => {
	return request('register', {
		data: {
			username,
			password,
			"userType": "app_user",
			avatar
		},
		noToken: true,
		loading: true,
		loadText: "正在注册...",
		showMessage: true,
		backAll: true
	})
}

// 登录函数，传入用户名和密码，返回请求结果
export const login = (username, password) => {
	return request("login", {
		method: "post",
		data: {
			username,
			password
		},
		noToken: true,
		loading: true,
		loadText: "正在登录..."
	})
}


// 上传文件函数，传入文件列表，返回一个Promise对象，解决时提供上传结果
export const uploadFile = (files) => {
	return file("system/oss/upload", files,"file")
}


export const updateAvatar = (files) => {
	return file("system/user/profile/avatar", files,"avatarfile")
}


// 获取用户信息函数，无参数，返回请求结果
export const getInfo = () => {
	return request("getInfo", {
		method: 'get'
	})
}

// 登出函数，无参数，返回请求结果
export const logout = () => {
	return request("logout")
}

// 更新密码函数，传入旧密码和新密码，返回请求结果
export const updatePwd = (oldPassword, newPassword) => {
	return request("system/user/profile/updatePwd", {
		method: 'put',
		data: {
			oldPassword,
			newPassword
		}
	})
}
export const getProfile=()=>{
	return request("system/user/profile",{
		method: 'get',
	})
}